const { MOCK } = require('../utils').settings
const axios = require('../utils/axios')
const { error } = require('../utils/error')
const {
  mockLogin,
  mockHistory,
  mockFans,
  mockRegister,
  mockAddAttention,
  mockAttention,
  mockEditPwd,
  mockEditUser,
  mockDynamic
} = require('./mock/user')
const apiError = (msg) => {
  error('50000', __dirname, msg)
}
// user - login
exports.requestLogin = async (data = {}) => {
  let result = MOCK ? mockLogin : await axios.post('/login', data)
  if (!result) {
    apiError('requestLogin')
    result = mockLogin
  }
  return result
}
// user - register
exports.requestRegister = async (data = {}) => {
  let result = MOCK ? mockRegister : await axios.post('/register', data)
  if (!result) {
    apiError('requestRegister')
    result = mockRegister
  }
  return result
}
// user - editUser
exports.requestEditUser = async (data = {}) => {
  let result = MOCK
    ? mockEditUser
    : await axios.post('/user/editUserData', data)
  if (!result) {
    apiError('requestEditUser')
    result = mockEditUser
  }
  return result
}
// user - editPwd
exports.requestEditPwd = async (data = {}) => {
  let result = MOCK ? mockEditPwd : await axios.post('/updatePwd', data)
  if (!result) {
    apiError('requestEditPwd')
    result = mockEditPwd
  }
  return result
}

// user - attention
exports.requestAttention = async (data = {}) => {
  let result = MOCK
    ? mockAttention
    : await axios.get('/user/getFollowList', {
        params: data
      })
  if (!result) {
    apiError('requestAttention')
    result = mockAttention
  }
  return result
}
// user - addAttention
exports.requestAddAttention = async (data = {}) => {
  let result = MOCK
    ? mockAddAttention
    : await axios.post('/user/toFollowOrCancel', data)
  if (!result) {
    apiError('requestAddAttention')
    result = mockAddAttention
  }
  return result
}
// user - fans
exports.requestFans = async (data = {}) => {
  let result = MOCK
    ? mockFans
    : await axios.get('/user/getFansList', {
        params: data
      })
  if (!result) {
    apiError('requestFans')
    result = mockFans
  }
  return result
}
// user - History
exports.requestHistory = async (data = {}) => {
  let result = MOCK
    ? mockHistory
    : await axios.get('/user/getBrowseList', {
        params: data
      })
  if (!result) {
    apiError('requestHistory')
    result = mockHistory
  }
  return result
}
// user - dynamic
exports.requestDynamic = async (data = {}) => {
  let result = MOCK
    ? mockDynamic
    : await axios.get('/user/getActionList', {
        params: data
      })
  // let result = await mockDynamic
  if (!result) {
    apiError('requestDynamic')
    result = mockDynamic
  }
  return result
}
